<?php
declare(strict_types=1);
/**
 * Created by PhpStorm
 * User: Administrator
 * Date: 2022/10/20
 * Time: 10:58:59
 */

namespace app\shop\controller;


use app\common\service\GoodsGroup\GoodsGroupService;
use app\Normal;
use app\Request;
use think\annotation\Route;
use think\annotation\route\Group;
use think\annotation\route\Middleware;

/**
 * 商品分组
 * @Group("GoodsGroup")
 * @Middleware({shopMiddileware::class})
 */
class GoodsGroup extends \app\BaseShopController
{
    /**
     * 列表
     * @Route("lists",method="GET")
     * @return \think\Response|\think\response\Json
     */
    public function lists(Request $request){
        $result = callApi(GoodsGroupService::class, 'lists',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 新增
     * @Route("add",method="POST")
     * @return void
     */
    public function add(Request $request){
        $result = callApi(GoodsGroupService::class, 'add',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'新增名称为【'.$this->_all_data['name'] . '】的商品分组','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 编辑名称
     * @Route("edit",method="PUT")
     * @return void
     */
    public function edit(Request $request){
        $result = callApi(GoodsGroupService::class, 'edit',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'修改ID为【'.$this->_all_data['id'] . '】的商品分组','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 商品分组商品列表
     * @Route("goodsLists/:id",method="GET")
     * @return void
     */
    public function goodsLists(Request $request){
        $result = callApi(GoodsGroupService::class, 'goodsLists',$this->_all_data);
        return apiResponse($result);
    }

    /**
     * 新增商品分组商品
     * @Route("addGroupGoods",method="POST")
     * @return void
     */
    public function addGroupGoods(Request $request){
        $result = callApi(GoodsGroupService::class, 'addGroupGoods',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'给ID为【'.$this->_all_data['id'] . '】的商品分组添加商品','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 批量移除商品分组商品
     * @Route("delGoods",method="POST")
     * @param Request $request
     * @return void
     */
    public function delGoods(Request $request){
        $result = callApi(GoodsGroupService::class, 'delGoods',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'删除ID为【'.$this->_all_data['id'] . '】的商品分组','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 改变状态
     * @Route("changeStatus",method="POST")
     * @param Request $request
     * @return \think\Response|\think\response\Json\
     */
    public function changeStatus(Request $request){
        $result = callApi(GoodsGroupService::class, 'changeStatus',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'改变ID为【'.$this->_all_data['id'] . '】的商品分组的状态','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }

    /**
     * 删除商品分组
     * @Route("delGoodsGroup",method="POST")
     * @param Request $request
     * @return \think\Response|\think\response\Json
     */
    public function delGoodsGroup(Request $request){
        $result = callApi(GoodsGroupService::class, 'delGoodsGroup',$this->_all_data);
        if($result['code'] == Normal::SUC){
            $this->log(['content'=>'删除ID为【'.$this->_all_data['id'] . '】的商品分组','request_param'=> json_encode($this->_all_data,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
        }
        return apiResponse($result);
    }
}